package com.cm.admin.controller;

import com.cm.admin.core.Token;
import com.cm.admin.service.AdminService;
import com.cm.admin.utils.JwtUtils;
import com.cm.common.core.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import static com.cm.admin.constrant.GlobalConstrant.TOKEN_PASSWORD;


/**
 * @类 名:IndexController </br>
 * @描 述:<br>
 * @日 期:2020/9/21 17:15 </br>
 * @作 者:小兰同学</br>
 * @版 本：1.0.0
 * @since JDK 1.8
 */
@RestController
@RequestMapping("/index")
public class IndexController {
    @Autowired
    private AdminService adminService;
    @PostMapping("/login")
    public Result login(String username, String password){
        if(adminService.login(username, password)){
            Token token = new Token();
            token.setToken(JwtUtils.sign(username,TOKEN_PASSWORD));
            return Result.success(token,"管理员登录成功");
        }else {
            return Result.fail("管理员登录失败");
        }
    }
}
